﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using snat.model;

namespace gui {

    /// <summary>
    /// GUI Notifiable Cluster to Colour Converter Class for WPF
    /// Converts a Cluster Node to a cluster colour based on its
    /// cluster ID
    /// </summary>
    [ValueConversion(typeof(int), typeof(string))]
    public class ClusterToColourConverter : IValueConverter {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            int id = (int)value;
            string colourStr;

            // If the cluster ID is not -1 or 0, then associate a colour with the node
            if (id > 0) {

                switch (id) {
                    case 1:
                        colourStr = "#FFFF0000";
                        break;
                    case 2: 
                        colourStr = "#FF00FF00";
                        break;
                    case 3: 
                        colourStr = "#FF0000FF";
                        break;
                    case 4: 
                        colourStr = "#FFFFCC00";
                        break;
                    case 5: 
                        colourStr = "#FFFF00CC";
                        break;
                    case 6: 
                        colourStr = "#FFCCFF00";
                        break;
                    case 7: 
                        colourStr = "#FFCC00FF";
                        break;
                    case 8: 
                        colourStr = "#FF00FFCC";
                        break;
                    case 9: 
                        colourStr = "#FF00CCFF";
                        break;
                    default:
                        // Find max number of clusters
                        float maxClusters = (float)10; // need to calculate this somehow <----
                        // Find max RGB colour in decimal form (256 colours per channel, 3 channels)
                        float maxColour = 16777216;
                        // Get Cluster Colour (as an even distribution of colours)
                        float colour = (id * (1 / maxClusters)) * maxColour;
                        // Add non-transparent element and convert to hex
                        colourStr = "#FF" + ((int)(colour)).ToString("X");
                        break;
                }
                return colourStr;

            } else {
                // Else the node is not associated with a cluster so assign a transparent highlight
                return "#00FFFFFF";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            throw new NotImplementedException();
        }
    }
}
